<template>
  <a @click="dialog = true">
    <span>设置日期</span>
    <a-modal v-model="dialog" title="预期到期日设置" @ok="submit">
      <a-form-model :form="form">
        <a-form-model-item prop="realEndTime"><a-date-picker v-model="form.realEndTime" /> </a-form-model-item>
      </a-form-model>
    </a-modal>
  </a>
</template>
<script>
import { updateProjectById } from '@/api/common'
import moment from 'moment'
import form from '@/locales/lang/en-US/form'
export default {
  name: 'setEndTime',
  props: ['record'],
  data() {
    return {
      dialog: false,
      updateProjectById,
      form: {
        realEndTime: ''
      }
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    async submit() {
      this.dialog = false
      const form = Object.assign({}, this.form)
      form.realEndTime = Number(form.realEndTime.startOf('day').format('X'))
      await updateProjectById(this.record.id, form)
      this.$emit('update')
    },
    getData() {
      if (this.record.realEndTime) {
        this.form.realEndTime = moment(this.record.realEndTime * 1000)
      } else if (this.record.sysEndTime) {
        this.form.realEndTime = moment(this.record.sysEndTime * 1000)
      } else {
        this.form.realEndTime = ''
      }
    }
  }
}
</script>
<style lang="css" scoped></style>
